// 准备好了
export function onPlayerReady(){
  console.log("准备好了");
}

// 视频播放
export function onPlayerPlay(player) {
  console.log('播放了');
  console.log(player);
  let playTime = 0;
  if (
    Number(Math.floor(this.playedTime)) ===
    Number(Math.floor(player.duration()))
  ) {
    this.playedTime = 0;
    playTime = 0;
  } else if (
    Number(Math.floor(player.currentTime())) !==
    Number(Math.floor(this.playedTime))
  ) {
    playTime = this.playedTime;
    player.currentTime(playTime)
  }
}

// 视频暂停的
export function onPlayerPause(player) {
  console.log('暂停中');
  console.log(player);
  this.playedTime = player.currentTime();
}

// 视频播放完
export function onPlayerEnd(player) {
  console.log('播放结束了');
  console.log(player);
}

// DOM元素上的readyState更改导致播放停止
export function onPlayerWaiting(player) {
  console.log("播放停止中");
  console.log(player);
}

// 视频已开始播放
export function onPlayerPlaying(player) {
  console.log("开始播放了");
  console.log(player);
}

// 当播放器在当前播放位置下载数据时触发
export function onPlayerLoadeddata(player) {
  console.log("开始下载数据");
  console.log(player);
}

// 当前播放位置发生变化时触发
export function onPlayerTimeupdate(player) {
  console.log("播放位置变化了");
  console.log(player);
  let timeDisplay = player.currentTime();
  if (timeDisplay - this.currentTime > 1) {
    player.currentTime(this.currentTime > this.maxTime ? this.currentTime : this.maxTime);
  }
  this.currentTime = player.currentTime();
  this.maxTime = this.currentTime > this.maxTime ? this.currentTime : this.maxTime;
}

//播放状态改变
export function playerStateChanged(playerCurrentState) {
  console.log("播放状态变化了");
  console.log(playerCurrentState);
}

// 手动暂停视频的播放
export function pause() {
  // 视频播放器的方法调用，要使用this.$refs.videoPlayer.player这个对象去调用
  this.$refs.videoPlayer.player.pause()
}
